package com.pxl.springbootinit.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pxl.springbootinit.common.BaseResponse;
import com.pxl.springbootinit.common.ResultUtils;
import com.pxl.springbootinit.model.dto.item.ItemLogisticsForm;
import com.pxl.springbootinit.model.vo.ItemLogisticsVO;
import com.pxl.springbootinit.service.ItemLogisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 物品物流接口
 *
 * @author MADAO
 * @create 2024 - 12 - 22 19:15
 */
@Slf4j
@RestController
@RequestMapping("/item/logistics")
public class ItemLogisticsController {
    @Resource
    private ItemLogisticsService itemLogisticsService;

    /**
     *  物品物流发货
     * @param itemLogisticsForm
     * @return
     */
    @PostMapping("/create")
    public BaseResponse<Boolean> createLogistics(@RequestBody ItemLogisticsForm itemLogisticsForm, HttpServletRequest request){
        return ResultUtils.success(itemLogisticsService.createLogistics(itemLogisticsForm,request));
    }

    /**
     * 分页查询商品及物流信息
     * @param itemLogisticsForm
     * @return
     */
   @GetMapping("/page")
    public BaseResponse<Page<ItemLogisticsVO>> pageLogistics(ItemLogisticsForm itemLogisticsForm, HttpServletRequest request){
       log.info("分页查询商品及物流信息:{} {} {}",itemLogisticsForm,itemLogisticsForm.getCurrent(),itemLogisticsForm.getPageSize());
        return ResultUtils.success(itemLogisticsService.pageLogistics(itemLogisticsForm,request));
    }


    @GetMapping("/receive")
    public BaseResponse<List<ItemLogisticsVO>> receiveLogisticsList(HttpServletRequest request){
        return ResultUtils.success(itemLogisticsService.receiveLogisticsList(request));
    }


    /**
     * 用户收货
     * @param id
     * @param request
     * @return
     */
    @PostMapping("/check/{id}")
    public BaseResponse<Boolean> checkLogistics(@PathVariable Long id, HttpServletRequest request){
        return ResultUtils.success(itemLogisticsService.checkLogistics(id,request));
    }

    //region 管理员

    @GetMapping("/admin/page")
    public BaseResponse<Page<ItemLogisticsVO>> pageLogisticsAdmin(ItemLogisticsForm itemLogisticsForm){
        return ResultUtils.success(itemLogisticsService.pageLogisticsAdmin(itemLogisticsForm));
    }

    //endregion
}
